home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / overview / win2maccountersamples / 2. counterwindow / source / ccounterapp.cp next >
Encoding:
Text File  |  2000-09-28  |  3.9 KB  |  156 lines

  1. /*
  2.     File:        CCounterApp.cp
  3.  
  4.     Contains:    Sample code to accompany Chapter 12 of 
  5.                 "An Introduction to Macintosh Programming for Windows Programmers".
  6.                 
  7.     Written by:    Worldwide Developer Technical Support
  8.  
  9.     Copyright:    1999 Apple Computer, Inc., All Rights Reserved
  10.  
  11.       You may incorporate this sample code into your applications without
  12.       restriction, though the sample code has been provided "AS IS" and the
  13.       responsibility for its operation is 100% yours.  However, what you are
  14.       not permitted to do is to redistribute the source as "DSC Sample Code"
  15.       after having made changes. If you're going to re-distribute the source,
  16.      we require that you make it clear in the source that the code was
  17.     descended from Apple Sample Code, but that you've made changes.
  18.     
  19. */
  20. #include "CCounterApp.h"
  21. #include "CounterConstants.h"
  22.  
  23. #include <LStaticText.h>
  24.  
  25. #include <LGrowZone.h>
  26. #include <LWindow.h>
  27. #include <PP_Messages.h>
  28. #include <PP_Resources.h>
  29. #include <PPobClasses.h>
  30. #include <UDrawingState.h>
  31. #include <UMemoryMgr.h>
  32. #include <URegistrar.h>
  33.  
  34. #include <UControlRegistry.h>
  35. #include <UGraphicUtils.h>
  36. #include <UEnvironment.h>
  37.  
  38. #ifndef __APPEARANCE__
  39. #include <Appearance.h>
  40. #endif
  41.  
  42. #include <Sound.h>
  43. #include <ToolUtils.h>
  44.  
  45. // ===========================================================================
  46. int main()
  47. {
  48.     SetDebugThrow_(debugAction_Alert);
  49.     SetDebugSignal_(debugAction_Alert);
  50.     InitializeHeap(3);                    // allocate 3 Master Pointer blocks
  51.     UQDGlobals::InitializeToolbox(&qd);
  52.     UEnvironment::InitEnvironment();
  53.     new LGrowZone(20000);            // For low memory situations.
  54.     CCounterApp    theApp;            // stack allocation
  55.     theApp.Run();
  56.     return 0;
  57. }
  58.  
  59. // ---------------------------------------------------------------------------
  60. CCounterApp::CCounterApp()
  61. {
  62.     if ( UEnvironment::HasFeature( env_HasAppearance ) ) {
  63.         ::RegisterAppearanceClient();
  64.     }
  65.     RegisterAllPPClasses();    // functions to create core PowerPlant classes
  66.     UControlRegistry::RegisterClasses();    // Appearance Manager/GA classes
  67. }
  68.  
  69.  
  70. // ---------------------------------------------------------------------------
  71. CCounterApp::~CCounterApp()
  72. {
  73. }
  74.  
  75. // ---------------------------------------------------------------------------
  76. //    This function lets you do something when the application starts up
  77. //    without a document.
  78. void
  79. CCounterApp::StartUp()
  80. {
  81.     LWindow* theWindow;
  82.     theWindow = MakeControlsWindow();    
  83.     ThrowIfNil_(theWindow );
  84. }
  85.  
  86. // ---------------------------------------------------------------------------
  87. //    Respond to commands from menus, buttons, etc.
  88. Boolean
  89. CCounterApp::ObeyCommand(CommandT    inCommand, void* ioParam)
  90. {
  91.     Boolean    cmdHandled = true;
  92.     switch (inCommand) {
  93.         case cmd_Increment:
  94. //            ::SysBeep(1);
  95.             fCounter.Increment();
  96.             fCaption->SetValue(fCounter.GetValue());
  97.             break;
  98.  
  99.  
  100.         case cmd_Decrement:
  101.             fCounter.Decrement();
  102.             fCaption->SetValue(fCounter.GetValue());
  103.             break;
  104.  
  105.         default:
  106.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  107.             break;
  108.     }
  109.     return cmdHandled;
  110. }
  111.  
  112. // ---------------------------------------------------------------------------
  113. //    This function enables menu commands.
  114. void
  115. CCounterApp::FindCommandStatus(
  116.     CommandT    inCommand,
  117.     Boolean        &outEnabled,
  118.     Boolean        &outUsesMark,
  119.     Char16        &outMark,
  120.     Str255        outName)
  121. {
  122.     switch (inCommand) {
  123.         // Return menu item status according to command messages.
  124.         case cmd_New:
  125. //            outEnabled = true;            // enable the New command
  126.             break;
  127.  
  128.         case cmd_Increment:
  129.             outEnabled = true;            // enable the button
  130.             break;
  131.  
  132.  
  133.         case cmd_Decrement:
  134.             outEnabled = true;            // enable the button
  135.             break;
  136.  
  137.         default:
  138.             LApplication::FindCommandStatus(inCommand, outEnabled,
  139.                                                 outUsesMark, outMark, outName);
  140.             break;
  141.     }
  142. }
  143.  
  144. // ---------------------------------------------------------------------------
  145. LWindow*
  146. CCounterApp::MakeControlsWindow()
  147. {
  148.     LWindow* theWindow = LWindow::CreateWindow(rWindow_Sample, this );
  149.     
  150.     fCaption = dynamic_cast<LCaption*>(theWindow->FindPaneByID(kCaption));
  151.     ThrowIfNil_(fCaption);
  152.         
  153.     theWindow->Show();
  154.     return theWindow;
  155. }
  156.